# 异常处理程序崩溃问题

# print("give me two numbers,and i'll divide them")
# print("enter q to quit")
# while True:
#     first_number = input("\n First number:")
#     if first_number == 'q':
#         break
#     second_number = input("Second number:")
#     if second_number == 'q':
#         break
#     answer = int(first_number) / int(second_number)
#     print(answer)

# 通过将可能引发错误的代码放在try-except代码块中，
# 可提高这个程序抵御错误的能力。
# 错误是执行除法运算的代码行导致的，因此我们需要将它放到try-except代码块中。
# 这个示例还包含一个else代码块；依赖于try代码块成功执行的代码都应放到else代码块中：

print("give me two numbers,and i'll divide them")
print("enter q to quit")
while True:
    first_number = input("\n First number:")
    if first_number == 'q':
        break
    second_number = input("Second number:")
    if second_number == 'q':
        break
    try:
        answer = int(first_number) / int(second_number)
    except ZeroDivisionError:
        print("you can't divide by 0")
    else:
        print(answer)
